package com.liu.lab03.Servlet;

import com.liu.lab03.dao.MusicDao;
import com.liu.lab03.pojo.Music;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

@WebServlet(name = "findMusicByInServlet", value = "/findMusicById")
public class FindMusicById extends HttpServlet {
    // 刘小文  -2420710103---
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取页面传过来的id
        int id = Integer.parseInt(request.getParameter("id"));
        //调用我们的dao findMusicById(id)
        //设置变量
        MusicDao mdao = new MusicDao();
        Music music = mdao.findMusicById(id);

        // ok 这里服务器已经收到数据了
        //我们把数据传送到页面中
        request.setAttribute("music", music);
        ServletContext servletContext = this.getServletContext();
        RequestDispatcher rd = servletContext.getRequestDispatcher("/updateMusic.jsp");
        rd.forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
